#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :file_demo.py
# @Time      :2023/6/30 
# @Author    :CL
# @email     :1037654919@qq.com

import json
import pandas as pd
import os
import shutil

def readname(filePath):
    # filePath = 'pinterest/'
    name = os.listdir(filePath)
    return name

def clean_data(filePath):
    global  clean_count
    "清洗pinterest数据，先在文件夹里边搜索jpg,批量删除不要的图片，再打开程序，运行程序，删除相应文件夹：判断逻辑：文件夹里边文件小于3"
    print('开始清洗：',filePath)
    name = readname(filePath)
    for i in name[:]:
        path2= filePath+'/{}/'.format(i)
        name2 = os.listdir(path2)
        if len(name2)<=2:
            shutil.rmtree(path2)
            print(i,len(name2))
            clean_count+=1
            continue
        flag =0
        for ss in name2:
            if 'thumb' in ss:
                flag =1
                print(ss)
                break
        if flag ==1:
            shutil.rmtree(path2)
            print(i,len(name2))
            clean_count+=1
            continue

def count_file(filePath):
    # filePath = 'pinterest/'
    name = os.listdir(filePath)
    return len(name)


if __name__ == "__main__":
    name = readname('behance/')
    print(name)
    clean_count=0
    count = 0
    for na in name:
        filepath = 'behance/{}/'.format(na)
        # clean_data(filepath)
        names = os.listdir(filepath)
        count+=len(names)
        for na2 in names:
            filepath2 = filepath + '{}/'.format(na2)
            file =  os.listdir(filepath2)
            count +=(int( len(file)) -1)/2
            # break

    print('count:',count)

